package com.tang.springboot_enable;

import com.tang.springboot_enable_other.Userconfig.MyImportBeanDefinit;
import com.tang.springboot_enable_other.Userconfig.MylmportSelector;
import com.tang.springboot_enable_other.Userconfig.Userconfig;
import com.tang.springboot_enable_other.domain.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import redis.clients.jedis.Jedis;

import java.util.Map;

@SpringBootApplication
/*@ComponentScan("com.tang.springboot_enable_other.Userconfig")*/
/*第一种方式 @ComponentScan 扫描范围:当前引导类所在的包以及子包*/
/*第二种方式 @Import :加载类,这些类都会被spring创建,并放到ioc容器*/
//@Import(User.class)
//@Import(MylmportSelector.class)
/*@Import(MyImportBeanDefinit.class)*/
/*@Import(Userconfig.class)*/
public class SpringbootEnableApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(SpringbootEnableApplication.class, args);
     /*   Object user = run.getBean(User.class);
        System.out.println(user);*/
/*
        Map<String, User> beansOfType = run.getBeansOfType(User.class);  //返回的是user是一个map形式的信息  {com.tang.springboot_enable_other.domain.User=com.tang.springboot_enable_other.domain.User@6f7923a5}
        System.out.println(beansOfType);*/
        Jedis jedis = run.getBean(Jedis.class);
        System.out.println(jedis);

        jedis.set("name","zhangsan");
        String name = jedis.get("name");
        System.out.println(name);
    }

    @Bean
    public Jedis jedis(){
        return  new Jedis();
    }
}
